package website.seamonster.ethegg.testdelay;



import org.apache.tomcat.jni.Time;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by 罗海量
 * 2018-07-17 17:43
 */
@lombok.extern.slf4j.Slf4j
public class ScheduledExecutorServiceTest {
    public static void main(String[] args) {
        System.out.println("hello world");
        System.out.println(Tst.service);
        Tst.service.schedule(()-> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("come on baby!");
            }, 3, TimeUnit.SECONDS);
        Tst.service.schedule(()-> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("come on baby!!");
        }, 3, TimeUnit.SECONDS);
        return;
    }
}

class Tst{
    //同一时间只有1个线程能执行
//    public static ScheduledExecutorService multiService= Executors.newSingleThreadScheduledExecutor();
    //可以设置同一时间能运行多少个线程
    public static ScheduledExecutorService service= Executors.newScheduledThreadPool(50);
}
